using UnityEngine;
using System.Collections;

[AddComponentMenu("TagMachine/Tools/Pause System")]
public class PauseSystem : MonoBehaviour
{
	private const float PAUSE_TIME 	= 0.5f;

	protected bool m_ChangeEnableOnPause = true;
	public bool ChangeEnableOnPause { get { return m_ChangeEnableOnPause; } }

	private bool m_IsPaused 		= false;
	public bool IsPaused 			{ get { return m_IsPaused; } }

	private float m_LastPause 		= -1.0f;

	// Update is called once per frame
	public void TogglePause()
	{
		if ( IsPaused )
		{
			Unpause();
		}
		else
		{
			Pause();
		}
	}

	public virtual void Pause()
	{
		float CurrentTime = Time.time;
		if ( CurrentTime - m_LastPause > PAUSE_TIME )
		{
			m_IsPaused 	= true;
			m_LastPause = CurrentTime;
			if ( ChangeEnableOnPause )
			{
				enabled 	= false;
			}
		}
	}

	public virtual void Unpause()
	{
		float CurrentTime = Time.time;
		if ( CurrentTime - m_LastPause > PAUSE_TIME )
		{
			m_IsPaused 	= false;
			m_LastPause = CurrentTime;
			if ( ChangeEnableOnPause )
			{
				enabled 	= true;
			}
		}	
	}
}

